//
//  certificationViewController.m
//  Edumap
//
//  Created by 辰领科技 on 16/7/19.
//  Copyright © 2016年 yuf. All rights reserved.
//

#import "certificationViewController.h"
#import "UIImagePickerController+Edit.h"
#import "UICustomActionSheet.h"

@interface certificationViewController ()
<UIActionSheetDelegate>

@property (strong, nonatomic) IBOutlet UILabel *titleLabel;
@property (strong, nonatomic) IBOutlet UIView *navView;
@property (strong, nonatomic) IBOutlet UIScrollView *scroview;
@property (strong, nonatomic) IBOutlet UITextField *nameTextField;//单位名称
@property (strong, nonatomic) IBOutlet UITextField *phoneNumberTextField;//联系电话
@property (strong, nonatomic) IBOutlet UITextField *addressTextField;//详细地址
@property (strong, nonatomic) IBOutlet UIButton *AddImageButtonOne;
@property (strong, nonatomic) NSString *imageOne;
@property (strong, nonatomic) IBOutlet UIButton *AddImageButtonTwo;
@property (strong, nonatomic) NSString *imageTwo;
@property (strong, nonatomic) IBOutlet UIButton *AddImageButtonThree;
@property (strong, nonatomic) NSString *imageThree;
@property (strong, nonatomic) IBOutlet UIButton *AddImageButtonFour;
@property (strong, nonatomic) NSString *imageFour;
@property (strong, nonatomic) IBOutlet UIButton *submitButton;
@property (strong, nonatomic) IBOutlet UIButton *backButton;

@property (assign, nonatomic) NSInteger count;
@property (assign, nonatomic) NSDictionary *dic;
@property (weak, nonatomic) IBOutlet UILabel *titleOne;
@property (weak, nonatomic) IBOutlet UILabel *titleTwo;
@property (weak, nonatomic) IBOutlet UILabel *titleThree;
@property (weak, nonatomic) IBOutlet UILabel *titleFour;

@end

@implementation certificationViewController

- (void)viewWillAppear:(BOOL)animated {
    [super viewWillAppear:animated];
    if (_certificationIdentifier == 0) {
        _titleLabel.text = @"机构信息";
        [self details];
        [_submitButton setTitle:@"保 存" forState:UIControlStateNormal];
        
    } else if (_certificationIdentifier == 1) {
        _titleLabel.text = @"实名认证";
        [_submitButton setTitle:@"提交审核" forState:UIControlStateNormal];
    }
}

- (void)viewDidLoad {
    [super viewDidLoad];
    
    [self initViewLayout];
}


- (void)initViewLayout{
    [self adaptiveViewLayout:self.view];
    [self adaptiveViewLayout:self.navView];
    [self adaptiveViewLayout:self.scroview];
    _scroview.contentSize = flexibleSize(CGSizeMake(0, 700), NO);
    _submitButton.layer.masksToBounds = YES;
    _submitButton.layer.cornerRadius = 5*VerticalRatio();
}

- (void)updateLayout {
    self.nameTextField.userInteractionEnabled = NO;
    self.phoneNumberTextField.userInteractionEnabled = NO;
    self.addressTextField.userInteractionEnabled = NO;
    [self.AddImageButtonOne setEnabled:NO];
    [self.AddImageButtonTwo setEnabled:NO];
    [self.AddImageButtonThree setEnabled:NO];
    [self.AddImageButtonFour setEnabled:NO];
    [self.submitButton setEnabled:NO];
   

    self.nameTextField.text = [NSString stringWithFormat:@"%@",_dic[@"msceName"]];
    self.phoneNumberTextField.text = [NSString stringWithFormat:@"%@",_dic[@"mscePhone"]];
    self.addressTextField.text = [NSString stringWithFormat:@"%@",_dic[@"msceAddr"]];
    
    NSString *msceIdcardFront = [NSString stringWithFormat:@"%@",self.dic[@"msceIdcardFront"]];
    if (msceIdcardFront && msceIdcardFront.length>0 && ![self.dic[@"msceIdcardFront"] isEqual:[NSNull null]]) {
        [self.AddImageButtonOne sd_setImageWithURL:[NSURL URLWithString:[NSString stringWithFormat:@"%@%@",IP_Address_ImageDown_Fresh,msceIdcardFront]] forState:UIControlStateNormal];
        _titleOne.hidden = YES;
       
    }
    NSString *msceIdcardBack = [NSString stringWithFormat:@"%@",self.dic[@"msceIdcardBack"]];
    if (msceIdcardBack && msceIdcardBack.length>0 && ![self.dic[@"msceIdcardBack"] isEqual:[NSNull null]]) {
        [self.AddImageButtonTwo sd_setImageWithURL:[NSURL URLWithString:[NSString stringWithFormat:@"%@%@",IP_Address_ImageDown_Fresh,msceIdcardBack]] forState:UIControlStateNormal];
        _titleTwo.hidden = YES;
    }
    NSString *msceLicense = [NSString stringWithFormat:@"%@",self.dic[@"msceLicense"]];
    if (msceLicense && msceLicense.length>0 && ![self.dic[@"msceLicense"] isEqual:[NSNull null]]) {
        [self.AddImageButtonThree sd_setImageWithURL:[NSURL URLWithString:[NSString stringWithFormat:@"%@%@",IP_Address_ImageDown_Fresh,msceLicense]] forState:UIControlStateNormal];
        _titleThree.hidden = YES;
        
    }
    NSString *msceQualification = [NSString stringWithFormat:@"%@",self.dic[@"msceQualification"]];
    if (msceQualification && msceQualification.length>0 && ![self.dic[@"msceQualification"] isEqual:[NSNull null]]) {
        [self.AddImageButtonFour sd_setImageWithURL:[NSURL URLWithString:[NSString stringWithFormat:@"%@%@",IP_Address_ImageDown_Fresh,msceQualification]] forState:UIControlStateNormal];
        _titleFour.hidden = YES;
        
    }

    
    NSString *msceStatus = [NSString stringWithFormat:@"%@",_dic[@"msceStatus"]];
    if ([msceStatus isEqualToString:@"1"]) {
        
        [self.submitButton setTitle:@"审核中" forState:UIControlStateNormal];
        
    } else if ([msceStatus isEqualToString:@"2"]) {
        
        [self.submitButton setTitle:@"已通过" forState:UIControlStateNormal];
        
    } else if ([msceStatus isEqualToString:@"3"]) {
        self.nameTextField.userInteractionEnabled = YES;
        self.phoneNumberTextField.userInteractionEnabled = YES;
        self.addressTextField.userInteractionEnabled = YES;
        [self.AddImageButtonOne setEnabled:YES];
        [self.AddImageButtonTwo setEnabled:YES];
        [self.AddImageButtonThree setEnabled:YES];
        [self.AddImageButtonFour setEnabled:YES];
        [self.submitButton setEnabled:YES];
        [self.submitButton setTitle:@"审核失败，请重新提交" forState:UIControlStateNormal];
    }
}

#pragma mark - 推广人员机构认证信息详情
- (void)details {
    NSMutableDictionary  *dic=[NSMutableDictionary dictionary];
    [dic setObject:[Common getLoginInfo][@"userId"] forKey:@"museId"];
    [dic setObject:[Common getLoginInfo][@"userId"] forKey:@"memberId"];
    [dic setObject:[Common getLoginInfo][Key_User_password] forKey:@"musePwd"];
    [dic setObject:[Common getLoginInfo][Key_User_onlineKey] forKey:@"museOnlineTag"];
    [dic setObject:_msceId forKey:@"msceId"];

    self.shareApi.delegate=self;
    [self.shareApi  requestOperationWithDic:dic withPath:JY_mallStoreCertificationDetails withHttpType:@"POST" withTag:JY_JY_mallStoreCertificationDetails];
}

- (IBAction)back:(id)sender {
    [self backBtn];
}

#pragma mark - 选择上传方式
- (IBAction)addImage:(UIButton *)sender {
    if (sender == _AddImageButtonOne) {
        
        _AddImageButtonOne.selected = YES;
        _AddImageButtonTwo.selected = NO;
        _AddImageButtonOne.selected = NO;
        _AddImageButtonTwo.selected = NO;
        _count = 1;
    } else if (sender == _AddImageButtonTwo) {
        
        _AddImageButtonOne.selected = NO;
        _AddImageButtonTwo.selected = YES;
        _AddImageButtonOne.selected = NO;
        _AddImageButtonTwo.selected = NO;
        _count = 2;
    } else if (sender == _AddImageButtonThree) {
        
        _AddImageButtonOne.selected = NO;
        _AddImageButtonTwo.selected = NO;
        _AddImageButtonOne.selected = YES;
        _AddImageButtonTwo.selected = NO;
        _count = 3;
    } else if (sender == _AddImageButtonFour) {
        
        _AddImageButtonOne.selected = NO;
        _AddImageButtonTwo.selected = NO;
        _AddImageButtonOne.selected = NO;
        _AddImageButtonTwo.selected = YES;
        _count = 4;
    }
    
    [self choosePhoto];
}



#pragma mark - 相关证件
- (void)choosePhoto{
    {
        PhotoPopView * photoPopView = [[PhotoPopView alloc]initWithcomplect:^(NSInteger index) {
            if ([[[UIDevice currentDevice] systemVersion] floatValue] >= 8.0) {
                UICustomActionSheet* actionSheet = [[UICustomActionSheet alloc] initWithTitle:@"" delegate:nil buttonTitles:@[@"",@""]];
                
                [actionSheet setButtonColors:@[[UIColor clearColor]]];
                [actionSheet setBackgroundColor:[UIColor clearColor]];
                
                [actionSheet setSubtitle:@""];
                [actionSheet setSubtitleColor:[UIColor clearColor]];
                
                [actionSheet showInView:self.view];
                
                UIImagePickerController *controller = [[UIImagePickerController alloc] init];
                __weak __typeof(self)weakSelf = self;
                [actionSheet hideAlert];
                if (index==0){
                    controller.allowsEditing = YES;
                    controller.sourceType = UIImagePickerControllerSourceTypeCamera;
                    
                    controller.finalizationBlock = ^(UIImagePickerController *picker, NSDictionary *info) {
                        
                        UIImage *image = info[UIImagePickerControllerEditedImage];
                        if (_count == 1) {
                            
                            [self.AddImageButtonOne setImage:image forState:UIControlStateNormal];
                            
                        } else if (_count == 2) {
                            
                            [self.AddImageButtonTwo setImage:image forState:UIControlStateNormal];
                            
                        } else if (_count == 3) {
                            
                            [self.AddImageButtonThree setImage:image forState:UIControlStateNormal];
                            
                        } else if (_count == 4) {
                            
                            [self.AddImageButtonFour setImage:image forState:UIControlStateNormal];
                            
                        }
                        [self imageUpload:1 :image];
                        // Dismiss when the crop mode was disabled
                        if (picker.cropMode == DZNPhotoEditorViewControllerCropModeNone) {
                            [weakSelf dismissViewControllerAnimated:NO completion:^{
                            }];
                        }
                    };
                    
                    controller.cancellationBlock = ^(UIImagePickerController *picker) {
                        
                        // Dismiss when the crop mode was disabled or if the navigation stack has only one child view controller.
                        if (picker.cropMode == DZNPhotoEditorViewControllerCropModeNone || picker.viewControllers.count == 1) {
                            [weakSelf dismissViewControllerAnimated:NO completion:^{
                            }];
                        }
                        else {
                            picker.cropMode = DZNPhotoEditorViewControllerCropModeCircular;
                            [picker popViewControllerAnimated:YES];
                        }
                    };
                    [self presentViewController:controller animated:NO completion:^{}];
                }else if (index==1){
                    controller.allowsEditing = YES;
                    controller.sourceType = UIImagePickerControllerSourceTypePhotoLibrary;
                    
                    controller.finalizationBlock = ^(UIImagePickerController *picker, NSDictionary *info) {
                        
                        UIImage *image = info[UIImagePickerControllerEditedImage];
                        if (_count == 1) {
                            
                            [self.AddImageButtonOne setImage:image forState:UIControlStateNormal];
                            
                        } else if (_count == 2) {
                            
                            [self.AddImageButtonTwo setImage:image forState:UIControlStateNormal];
                            
                        } else if (_count == 3) {
                            
                            [self.AddImageButtonThree setImage:image forState:UIControlStateNormal];
                            
                        } else if (_count == 4) {
                            
                            [self.AddImageButtonFour setImage:image forState:UIControlStateNormal];
                            
                        }
                        [self imageUpload:1 :image];
                        // Dismiss when the crop mode was disabled
                        if (picker.cropMode == DZNPhotoEditorViewControllerCropModeNone) {
                            [weakSelf dismissViewControllerAnimated:NO completion:^{
                            }];
                        }
                    };
                    
                    controller.cancellationBlock = ^(UIImagePickerController *picker) {
                        
                        // Dismiss when the crop mode was disabled or if the navigation stack has only one child view controller.
                        if (picker.cropMode == DZNPhotoEditorViewControllerCropModeNone || picker.viewControllers.count == 1) {
                            [weakSelf dismissViewControllerAnimated:NO completion:^{
                            }];
                        }
                        else {
                            picker.cropMode = DZNPhotoEditorViewControllerCropModeCircular;
                            [picker popViewControllerAnimated:YES];
                        }
                    };
                    [self presentViewController:controller animated:NO completion:^{}];
                }
                
                
                
                
            }else {
                UIActionSheet *ss=[[UIActionSheet alloc] initWithTitle:nil delegate:self cancelButtonTitle:@"" destructiveButtonTitle:@"" otherButtonTitles:@"", nil];
                [ss showInView:self.view];
                UIImagePickerController *controller = [[UIImagePickerController alloc] init];
                __weak __typeof(self)weakSelf = self;
                [ss dismissWithClickedButtonIndex:0 animated:YES];
                if (index==0){
                    controller.allowsEditing = YES;
                    controller.sourceType = UIImagePickerControllerSourceTypeCamera;
                    
                    controller.finalizationBlock = ^(UIImagePickerController *picker, NSDictionary *info) {
                        
                        UIImage *image = info[UIImagePickerControllerEditedImage];
                        if (_count == 1) {
                            
                            [self.AddImageButtonOne setImage:image forState:UIControlStateNormal];
                            
                        } else if (_count == 2) {
                            
                            [self.AddImageButtonTwo setImage:image forState:UIControlStateNormal];
                            
                        } else if (_count == 3) {
                            
                            [self.AddImageButtonThree setImage:image forState:UIControlStateNormal];
                            
                        } else if (_count == 4) {
                            
                            [self.AddImageButtonFour setImage:image forState:UIControlStateNormal];
                            
                        }
                        [self imageUpload:1 :image];
                        // Dismiss when the crop mode was disabled
                        if (picker.cropMode == DZNPhotoEditorViewControllerCropModeNone) {
                            [weakSelf dismissViewControllerAnimated:NO completion:^{
                            }];
                        }
                    };
                    
                    controller.cancellationBlock = ^(UIImagePickerController *picker) {
                        
                        // Dismiss when the crop mode was disabled or if the navigation stack has only one child view controller.
                        if (picker.cropMode == DZNPhotoEditorViewControllerCropModeNone || picker.viewControllers.count == 1) {
                            [weakSelf dismissViewControllerAnimated:NO completion:^{
                            }];
                        }
                        else {
                            picker.cropMode = DZNPhotoEditorViewControllerCropModeCircular;
                            [picker popViewControllerAnimated:YES];
                        }
                    };
                    [self presentViewController:controller animated:NO completion:^{}];
                }else if (index==1){
                    controller.allowsEditing = YES;
                    controller.sourceType = UIImagePickerControllerSourceTypePhotoLibrary;
                    
                    controller.finalizationBlock = ^(UIImagePickerController *picker, NSDictionary *info) {
                        
                        UIImage *image = info[UIImagePickerControllerEditedImage];
                        if (_count == 1) {
                            
                            [self.AddImageButtonOne setImage:image forState:UIControlStateNormal];
                            
                        } else if (_count == 2) {
                            
                            [self.AddImageButtonTwo setImage:image forState:UIControlStateNormal];
                            
                        } else if (_count == 3) {
                            
                            [self.AddImageButtonThree setImage:image forState:UIControlStateNormal];
                            
                        } else if (_count == 4) {
                            
                            [self.AddImageButtonFour setImage:image forState:UIControlStateNormal];
                            
                        }
                        [self imageUpload:1 :image];
                        // Dismiss when the crop mode was disabled
                        if (picker.cropMode == DZNPhotoEditorViewControllerCropModeNone) {
                            [weakSelf dismissViewControllerAnimated:NO completion:^{
                            }];
                        }
                    };
                    
                    controller.cancellationBlock = ^(UIImagePickerController *picker) {
                        
                        // Dismiss when the crop mode was disabled or if the navigation stack has only one child view controller.
                        if (picker.cropMode == DZNPhotoEditorViewControllerCropModeNone || picker.viewControllers.count == 1) {
                            [weakSelf dismissViewControllerAnimated:NO completion:^{
                            }];
                        }
                        else {
                            picker.cropMode = DZNPhotoEditorViewControllerCropModeCircular;
                            [picker popViewControllerAnimated:YES];
                        }
                    };
                    [self presentViewController:controller animated:NO completion:^{}];
                }
                
                
                
            }
            
        }];
        [photoPopView show];
    }


}

#pragma mark - 上传图片--------------------------
- (void) imageUpload:(int)numberImg:(UIImage *)imageImage{
    NSString *url = [NSString stringWithFormat:@"%@",IP_Address_IMAGE];
    //分界线的标识符
    NSString *TWITTERFON_FORM_BOUNDARY = @"AaB03x";
    //根据url初始化request
    NSMutableURLRequest* request = [NSMutableURLRequest requestWithURL:[NSURL URLWithString:url]
                                                           cachePolicy:NSURLRequestReloadIgnoringLocalCacheData
                                                       timeoutInterval:10];
    //分界线 --AaB03x
    NSString *MPboundary=[[NSString alloc]initWithFormat:@"--%@",TWITTERFON_FORM_BOUNDARY];
    //结束符 AaB03x--
    NSString *endMPboundary=[[NSString alloc]initWithFormat:@"%@--",MPboundary];
    //要上传的图片
    //    UIImage *image=[params objectForKey:@"pic"];
    //得到图片的data
    CGSize newSize = CGSizeMake(80, 80);
    UIGraphicsBeginImageContext(newSize);
    [imageImage drawInRect:CGRectMake(0,0,newSize.width,newSize.height)];
    UIImage* newImage = UIGraphicsGetImageFromCurrentImageContext();
    UIGraphicsEndImageContext();
    NSData* data  = UIImageJPEGRepresentation(newImage, 0.7);
    //http body的字符串
    NSMutableString *body=[[NSMutableString alloc]init];
    //设置HTTPHeader中Content-Type的值
    NSString* content=[[NSString alloc]initWithFormat:@"multipart/form-data; boundary=%@",TWITTERFON_FORM_BOUNDARY];
    ////添加分界线，换行
    [body appendFormat:@"%@\r\n",MPboundary];
    //声明pic字段，文件名为boris.png
    [body appendFormat:@"Content-Disposition: form-data; name=\"pic\"; filename=\"boris.png\"\r\n"];
    //声明上传文件的格式
    [body appendFormat:@"Content-Type: image/png\r\n\r\n"];
    //    [body appendFormat:@"Content-Type: %@\r\n\r\n",content];
    //声明结束符：--AaB03x--
    NSString *end=[[NSString alloc]initWithFormat:@"\r\n%@",endMPboundary];
    //声明myRequestData，用来放入http body
    NSMutableData *myRequestData=[NSMutableData data];
    //将body字符串转化为UTF8格式的二进制
    [myRequestData appendData:[body dataUsingEncoding:NSUTF8StringEncoding]];
    //将image的data加入
    [myRequestData appendData:data];
    //加入结束符--AaB03x--
    [myRequestData appendData:[end dataUsingEncoding:NSUTF8StringEncoding]];
    NSString *headerUserAgent=@"";
    if ([Common getLoginStatus]) {
        NSString *userName = [[Common getLoginInfo] objectForKey:Key_User_nickname];
        NSString *userId  = [NSString stringWithFormat:@"%@",[[Common getLoginInfo] objectForKey:Key_User_userId]];
        NSString *encryptPwd  = [ [Common getLoginInfo] objectForKey:Key_User_password];
        NSString *localUserIdentify  = [[UIDevice currentDevice].identifierForVendor UUIDString];
        headerUserAgent = [NSString stringWithFormat:@"%@|%@|%@|%@",userName,userId,encryptPwd,localUserIdentify];
    }else{
        headerUserAgent = @"|||";
    }
    
    //设置HTTPHeader
    [request setValue:content forHTTPHeaderField:@"Content-Type"];
    //设置User-Agent
    [request setValue:headerUserAgent forHTTPHeaderField:@"User-Agent"];
    //设置Content-Length
    [request setValue:[NSString stringWithFormat:@"%d", [myRequestData length]] forHTTPHeaderField:@"Content-Length"];
    //设置http body
    [request setHTTPBody:myRequestData];
    //http method
    [request setHTTPMethod:@"POST"];
    
    //建立连接，设置代理
    //    NSURLConnection *conn = [[NSURLConnection alloc] initWithRequest:request delegate:self];
    //上传文件开始
    NSData *returnData = [NSURLConnection sendSynchronousRequest:request returningResponse:nil error:nil];
    //获得返回值
    NSString *returnString = [[NSString alloc] initWithData:returnData encoding:NSUTF8StringEncoding];
    
    NSData *jsonData = [returnString dataUsingEncoding:NSUTF8StringEncoding];
    NSError *error = nil;
    NSMutableDictionary *dictionary = [[CJSONDeserializer deserializer] deserializeAsDictionary:jsonData error:&error];
    
    //取得返回的图片名
    //    NSArray* array = [returnString componentsSeparatedByString:@"###"];
    //    NSString * image = [NSString stringWithFormat:@"%@", dictionary[@"result"][0][@"simaId"]];
    NSString * image = dictionary[@"title"];
    if (_count == 1) {
        if (image.length>0){
            _imageOne = image;
        }else{
            _imageOne = @"";
        }
    } else if (_count == 2) {
        if (image.length>0){
            _imageTwo = image;
        }else{
            _imageTwo = @"";
        }
    } else if (_count == 3) {
        if (image.length>0){
            _imageThree = image;
        }else{
            _imageThree = @"";
        }
    } else if (_count == 4) {
        if (image.length>0){
            _imageFour = image;
        }else{
            _imageFour = @"";
        }
    }
    
    
}



#pragma mark - 提交审核
- (IBAction)submit:(id)sender {
 
    if (_nameTextField.text.length==0) {
        [CWHUDTips showTips:_nameTextField.placeholder];
        return;
    }
    if (_phoneNumberTextField.text.length==0) {
        [CWHUDTips showTips:_phoneNumberTextField.placeholder];
        return;
    }
    if (_imageOne.length==0) {
        [CWHUDTips showTips:@"请添加身份证正面图片"];
        return;
    }
    if (_imageTwo.length==0) {
        [CWHUDTips showTips:@"请添加身份证背面图片"];
        return;
    }
    if (_imageThree.length==0) {
        [CWHUDTips showTips:@"请添加从业资格证正面图片"];
        return;
    }
    if (_imageFour.length==0) {
        [CWHUDTips showTips:@"请添加从业资格证背面图片"];
        return;
    }
    
    if (_certificationIdentifier == 0) {
        NSMutableDictionary  *dic=[NSMutableDictionary dictionary];
        [dic setObject:[Common getLoginInfo][@"userId"] forKey:@"museId"];
        [dic setObject:[Common getLoginInfo][@"userId"] forKey:@"msceMemberId"];
        [dic setObject:[Common getLoginInfo][Key_User_password] forKey:@"musePwd"];
        [dic setObject:[Common getLoginInfo][Key_User_onlineKey] forKey:@"museOnlineTag"];
        [dic setObject:self.nameTextField.text forKey:@"msceName"];
        [dic setObject:self.phoneNumberTextField.text forKey:@"mscePhone"];
        [dic setObject:_imageOne forKey:@"msceIdcardFront"];
        [dic setObject:_imageTwo forKey:@"msceIdcardBack"];
        [dic setObject:_imageThree forKey:@"msceLicense"];
        [dic setObject:_imageFour forKey:@"msceQualification"];
        [dic setObject:_dic[@"msceStoreId"] forKey:@"msceStoreId"];
        [dic setObject:_dic[@"msceStatus"] forKey:@"msceStatus"];
        self.shareApi.delegate=self;
        [self.shareApi  requestOperationWithDic:dic withPath:JY_mallStoreCertificationEdit withHttpType:@"POST" withTag:JY_JY_mallStoreCertificationEdit];


        
    } else if (_certificationIdentifier == 1) {
        NSMutableDictionary  *dic=[NSMutableDictionary dictionary];
        [dic setObject:[Common getLoginInfo][@"userId"] forKey:@"museId"];
        [dic setObject:[Common getLoginInfo][@"userId"] forKey:@"msceMemberId"];
        [dic setObject:[Common getLoginInfo][Key_User_password] forKey:@"musePwd"];
        [dic setObject:[Common getLoginInfo][Key_User_onlineKey] forKey:@"museOnlineTag"];
        
        [dic setObject:self.nameTextField.text forKey:@"msceName"];
        [dic setObject:self.phoneNumberTextField.text forKey:@"mscePhone"];
        [dic setObject:self.addressTextField.text forKey:@"msceAddr"];
        [dic setObject:_imageOne forKey:@"msceIdcardFront"];
        [dic setObject:_imageTwo forKey:@"msceIdcardBack"];
        [dic setObject:_imageThree forKey:@"msceLicense"];
        [dic setObject:_imageFour forKey:@"msceQualification"];
        self.shareApi.delegate=self;
        [self.shareApi  requestOperationWithDic:dic withPath:JY_addMallStoreCertification withHttpType:@"POST" withTag:JY_JY_addMallStoreCertification];
    }

}


#pragma   mark---- GetADBanner Request Delegate

-(void)fetchDatabaseFinished:(NSMutableDictionary *)database withTag:(NSInteger)tag{
    
    if (tag==JY_JY_addMallStoreCertification) {
        
        if (  [[database valueForKey:@"flag"] integerValue]!=1 ) {
            
            [[CWHUDTips sharedInstance]  showTips:[database valueForKey:@"msg"]  withStatus:1 dismissAfter:1.5];
            
        }else  {
            [[Common getNavigation]popViewController];
            
        }
    } else if (tag==JY_JY_mallStoreCertificationDetails) {
        
        if (  [[database valueForKey:@"flag"] integerValue]!=1 ) {
            
            [[CWHUDTips sharedInstance]  showTips:[database valueForKey:@"msg"]  withStatus:1 dismissAfter:1.5];
            
        }else  {
            _dic = [NSDictionary dictionary];
            _dic = database[@"result"];
            [self updateLayout];
        }
    } else if (tag==JY_JY_mallStoreCertificationEdit) {
        
        if (  [[database valueForKey:@"flag"] integerValue]!=1 ) {
            
            [[CWHUDTips sharedInstance]  showTips:[database valueForKey:@"msg"]  withStatus:1 dismissAfter:1.5];
            
        }else  {
            [[Common getNavigation]popViewController];
        }
    }
}
-(void)fetchDatabaseFailed:(NSError *)error message:(NSString *)message{
    
    //
    [self dismissWaitDialog];
    
    
}

@end
